package echat.future.cn.echat.message.weekrank.adapter;

import android.graphics.Color;
import android.support.annotation.Nullable;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.netease.nim.avchatkit.common.log.LogUtil;

import java.util.List;

import echat.future.cn.echat.R;
import echat.future.cn.echat.message.bean.WeekRankBean;
import echat.future.cn.echat.my.weight.CircleImageView;

/**
 * Created by JX on 2018/8/27.
 */

public class WeekRankAdapter extends BaseQuickAdapter<WeekRankBean, BaseViewHolder> {

    private int mType = 2;

    public WeekRankAdapter(int layoutResId, @Nullable List<WeekRankBean> data) {
        super(layoutResId, data);
    }

    public void setType(int type) {
        this.mType = type;
    }

    @Override
    protected void convert(BaseViewHolder helper, WeekRankBean item) {
        RequestOptions options = new RequestOptions();
        options.centerCrop()
                .placeholder(R.mipmap.ic_launcher);
        Glide.with(mContext).load(item.getAvatar()).apply(options).into((CircleImageView)helper.getView(R.id.iv_head));
        helper.setText(R.id.tv_position, String.valueOf(helper.getLayoutPosition() + 3));
        String text = mType == 2 ? "收获" + item.getSum() + "个" : "送出" + item.getSum() + "个";
        ((TextView)helper.getView(R.id.tv_number)).setText(getSpannable(text));
        helper.setText(R.id.tv_name, item.getUsername());
    }

    private SpannableStringBuilder getSpannable(String text) {
        SpannableStringBuilder spannable = new SpannableStringBuilder(text);
        spannable.setSpan(new ForegroundColorSpan(Color.parseColor("#F35043")),2,text.length()-1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        return spannable;
    }
}
